package VUDUYTUNG;

import java.util.Scanner;

public class HOMEWORK_02 {

	public static void main(String[] args) {

		// Input a,b
		String a, b, pheptoan;

		Scanner in = new Scanner(System.in);

		// Read input, check null

		do {
			System.out.println("Nhap a = ");
			a = in.nextLine();
			System.out.println("Nhap b = ");
			b = in.nextLine();

			if (a.isEmpty() && b.isEmpty()) {
				System.out.println("Ban chua nhap so");
			}

		} while (a.isEmpty() || b.isEmpty());

		double m = Double.parseDouble(a.trim());
		double n = Double.parseDouble(b.trim());

		do {
			System.out.println("Xin hay chon phep toan (cong/tru/nhan/chia): ");
			pheptoan = in.nextLine();

			if (pheptoan.isEmpty()) {
				System.out.println("Ban chua cho phep toan.");
			}
			

		} while (pheptoan.isEmpty());

		if (pheptoan.contentEquals("cong")) {
			System.out.println("Ket qua la " + (m + n));

		} 
		
		else if (pheptoan.contentEquals("tru")) {
			System.out.println("Ket qua la " + (m - n));
		}

		else if (pheptoan.contentEquals("nhan")) {
			System.out.println("Ket qua la " + (m * n));
		}

		else if (pheptoan.contentEquals("chia")) {
			if (m == 0 && n == 0) {
				System.out.println("Result of function is undefined");
			} else if (n == 0) {
				System.out.println("Cannot divided by zero");
			} else {
				System.out.println("Ket qua la " + (m / n));
			}

		}
	}
}
